﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace hextrans
{

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Byte[] buffer = new Byte[21];
            Class1line Aline = new Class1line();
            OpenFileDialog Orient_f = new OpenFileDialog();
            Orient_f.InitialDirectory = @"c:\";
            Orient_f.RestoreDirectory = true;
            Orient_f.Filter = "hex文件(*.hex)|*.hex";
            // Orient_f.ShowDialog();
            if (Orient_f.ShowDialog() == DialogResult.OK)
            {
                this.button1.Text = Orient_f.FileName;

                StreamReader strRead = File.OpenText(@Orient_f.FileName);
                string duqu;
                duqu = strRead.ReadLine();
                while (duqu != null)
                {
                    // duqu = duqu.Replace( "\r\n","\n");
                    //  richTextBox1.Text += duqu + "\n";
                    richTextBox1.Text += duqu + "\n";
                    // buffer = Convert.ToByte(duqu);
                    Aline.Reload(duqu);
                    duqu = Aline.Offset(0x10);
                    richTextBox2.Text += duqu + "\n";
                    duqu = strRead.ReadLine();
                    //  richTextBox1.Text += duqu + "\n";
                }
            }

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void richTextBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "hex文件(*.hex)|*.hex";

            saveFileDialog.RestoreDirectory = true;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {

                string fName = saveFileDialog.FileName;
                StreamWriter stw = File.CreateText(fName);
               // File fSaveAs = new File(fName);

               // isFileHaveName = true;

                stw.Write(richTextBox2.Text);
                stw.Close();

            }
        }
    }
}
